package com.dq.domain.sys.user;

import com.dq.vo.Vo;
import com.dq.domain.base.BaseEntity;
import com.dq.domain.orders.UserOrder;
import com.dq.domain.sys.user.user.base.SysUser;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import com.dq.vo.baseVo.VO;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.ManyToOne;

/**
 * @author liuhui
 * @date 2019/9/1917:05
 */
@Data
@Entity
@ApiModel("积分记录")
public  class Integral extends BaseEntity implements Vo.ToVO {

    @ApiModelProperty("用户")
    @ManyToOne
    protected SysUser user;

    @ApiModelProperty("积分来源类型")
    @Enumerated(EnumType.ORDINAL)
    protected ChangeIntegralType ciType;

    @ApiModelProperty("积分变动类型")
    @Enumerated(EnumType.ORDINAL)
    protected ChangeType changeType;

    @ApiModelProperty("积分变更数量")
    protected Long changeNum;

    @ApiModelProperty("关联销售单")
    @ManyToOne
    protected UserOrder userOrder;


    public enum ChangeType {
        add("加"),
        less("减"),;
        public String mean;

        ChangeType(String mean) {
            this.mean = mean;
        }
    }

    public enum ChangeIntegralType {
        buyinteg("消费获得"),
        deduction("服务抵扣"),
        goods("购买积分商品");

        ChangeIntegralType(String name) {
            this.name = name;
        }

        public String name;
    }


    @Data
    @ApiModel(value = "积分视图")
    public static class Vo implements VO {
    }
    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo=new Vo();
        return vo;
    }

    @Data
    @ApiModel("积分记录")
    public static class IntegralList{
        @ApiModelProperty("积分来源类型")
        protected String ciType;

        @ApiModelProperty("积分变动类型")
        protected String changeType;

        @ApiModelProperty("积分变更数量")
        protected Long changeNum;

        @ApiModelProperty("创建时间")
        protected String createTime;
    }

    public IntegralList toIntegralList(){
        IntegralList vo = new IntegralList();
        vo.ciType = this.ciType.name;
        vo.changeType = this.changeType.mean;
        vo.changeNum = this.changeNum;
        vo.createTime = fmt(this.createTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        return vo;
    }
}
